import '../../index.dart';

class FeedbackPage extends StatefulWidget {
  const FeedbackPage({Key? key}) : super(key: key);

  @override
  State<FeedbackPage> createState() => _FeedbackPageState();
}

class _FeedbackPageState extends State<FeedbackPage> {
  //表单状态
  final _formKey = GlobalKey<FormState>();

  //焦点
  final FocusNode _focusNode = FocusNode();

  var _value = '';

  String? validate(value) {
    if (value.isEmpty) {
      return '请输入意见反馈';
    } else if (value.trim().length > 200) {
      return '意见反馈不能超过200字';
    }
    return null;
  }

  @override
  Widget build(BuildContext context) {
    return GlobalStyle(
      child: BackgroundStyleWidget(
        child: Scaffold(
          backgroundColor: Theme.of(context).colorScheme.surface,
          appBar: AppBar(
            leading: IconButton(
              icon:
                  Image.asset('images/common_left.png', width: 16, height: 16),
              onPressed: () {
                Navigator.of(context).pop();
              },
            ),
            title: const Text('意见反馈'),
            centerTitle: true,
          ),
          body: Column(
            children: [
              const SizedBox(height: 6),
              Container(
                width: double.infinity,
                height: 260,
                padding: EdgeInsets.all(16),
                color: Theme.of(context).colorScheme.background,
                child: TextField(
                    autofocus: true,
                    maxLines: 10,
                    decoration: const InputDecoration(
                      contentPadding:
                          EdgeInsets.symmetric(horizontal: 10, vertical: 0),
                      hintText: '请输入200个字意见反馈...',
                      hintStyle:
                          TextStyle(color: Color.fromRGBO(209, 209, 209, 1)),
                      border: OutlineInputBorder(borderSide: BorderSide.none),
                    ),
                    onChanged: (value) {
                      _value = value;
                    }),
              ),
              Container(
                width: double.infinity,
                padding: EdgeInsets.all(16),
                child: CommonButton.elevatedButton(context, text: "确定",
                    onPressed: () {
                  if (!_value.isNotEmpty) {
                    showToast('请填写意见反馈');
                    return;
                  }
                  showDialog(
                      context: context,
                      builder: (context) {
                        return AlertDialog(
                          title: const Text('反馈成功'),
                          content: const Text('感谢您的反馈，我们会持续优化产品！'),
                          actions: <Widget>[
                            TextButton(
                              child: const Text('确认'),
                              onPressed: () {
                                Navigator.of(context).pop();
                              },
                            ),
                          ],
                        );
                      });
                }),
              ),
            ],
          ),
        ),
      ),
      // Form(
      //   key: _formKey,
      //   child: Container(
      //     padding: const EdgeInsets.all(20),
      //     child: Column(
      //       children: [
      //         TextFormField(
      //           autofocus: true,
      //           //  自动获取焦点
      //           maxLines: 5,
      //           decoration: const InputDecoration(
      //             hintText: '请输入意见反馈',
      //             border: OutlineInputBorder(),
      //           ),
      //           focusNode: _focusNode,
      //           //验证用户名
      //           validator: validate,
      //           //保存数据
      //           onChanged: (value) {
      //             _value = value;
      //           },
      //         ),
      //         const SizedBox(height: 20),
      //         SizedBox(
      //           width: double.infinity,
      //           height: 40,
      //           child: ElevatedButton(
      //             child: const Text('确定'),
      //             onPressed: () {
      //               _focusNode.unfocus();
      //               if (_formKey.currentState!.validate()) {
      //                 print(_value);
      //                 showDialog(
      //                     context: context,
      //                     builder: (context) {
      //                       return AlertDialog(
      //                         title: const Text('反馈成功'),
      //                         content: const Text('感谢您的反馈，我们会持续优化产品！'),
      //                         actions: <Widget>[
      //                           TextButton(
      //                             child: const Text('确认'),
      //                             onPressed: () {
      //                               Navigator.of(context).pop();
      //                             },
      //                           ),
      //                         ],
      //                       );
      //                     });
      //               }
      //             },
      //           ),
      //         ),
      //       ],
      //     ),
      //   ),
      // ),
    );
  }
}
